package com.handpay.zztong.hp.qualification.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.handpay.framework.LuaTableUtil;
import com.handpay.zztong.hp.log.HPLog;

import java.util.Vector;

import se.krka.kahlua.vm.LuaTable;

public class PicPreviewInfo implements Parcelable {

    public String picId;
    public String picUrl;

    public PicPreviewInfo() {
        super();
    }

    public PicPreviewInfo(String picId, String picUrl) {
        super();
        this.picId = picId;
        this.picUrl = picUrl;
    }

    public PicPreviewInfo(String picUrl) {
        super();
        this.picUrl = picUrl;
    }

    public static PicPreviewInfo[] getPicPreviewsArray(LuaTable luaTable, int items) {
        PicPreviewInfo[] pps = null;
        if (items > 0) {
            LuaTable list = (LuaTable) luaTable.rawget("list");
            if (list != null) {
                Vector<LuaTable> dataList = LuaTableUtil.getArray(list);
                pps = new PicPreviewInfo[dataList.size()];
                HPLog.i(HPLog.LFP_TAG, dataList.size());
                for (int i = 0; i < dataList.size(); i++) {
                    PicPreviewInfo info = new PicPreviewInfo();
                    String picId = (String) dataList.get(i).rawget("picId");
                    String picUrl = (String) dataList.get(i).rawget("picUrl");
                    HPLog.i(HPLog.LFP_TAG, "picUrl=" + picUrl);
                    info.picId = picId;
                    info.picUrl = picUrl;
                    pps[i] = info;
                }
            }
        }
        return pps;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.picId);
        dest.writeString(this.picUrl);
    }

    protected PicPreviewInfo(Parcel in) {
        this.picId = in.readString();
        this.picUrl = in.readString();
    }

    public static final Parcelable.Creator<PicPreviewInfo> CREATOR = new Parcelable.Creator<PicPreviewInfo>() {
        @Override
        public PicPreviewInfo createFromParcel(Parcel source) {
            return new PicPreviewInfo(source);
        }

        @Override
        public PicPreviewInfo[] newArray(int size) {
            return new PicPreviewInfo[size];
        }
    };
}
